#region imports

using System;
using System.ComponentModel;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using MimeCloud.AssetManagement.Business.Interface;

#endregion

namespace MimeCloud.AssetManagement.Business
{
    [Serializable]
    public class Asset : IAsset
    {
        #region properties

        [XmlElement ( "id" )]
        public int ID { get; set; }

        [XmlElement ( "name" )]
        public string Name { get; set; }

        [XmlIgnore]
        public int StatusID { get; set; }

        [XmlElement ( "source" )]
        public string Source { get; set; }

        [XmlElement ( "creationdate" )]
        public DateTime CreationDate { get; set; }

        [XmlElement ( "updateddate" )]
        public DateTime UpdatedDate { get; set; }

        [XmlElement ( "creatorid" )]
        public string CreatorID { get; set; }

        [XmlElement ( "latesteditorid" )]
        public string LatestEditorID { get; set; }

        [XmlElement ( "assetrightsusagelist" )]
        public IList<IAssetRightsUsage> AssetRightsUsageList { get; set; }

        [XmlElement ( "relatedassetlist" )]
        public IList<IRelatedAsset> RelatedAssetList { get; set; }

        [XmlElement ( "associatedcontentlist" )]
        public IList<IAssociatedContent> AssociatedContentList { get; set; }

        [XmlElement ( "assetmetadatalist" )]
        public IList<IMetaData> AssetMetaDataList { get; set; }

        [XmlElement ( "assetcontentlist" )]
        public IList<IAssetContent> AssetContentList { get; set; }

        public Guid InstanceID
        {
            get; set;
        }

        [XmlElement ( "status" )]
        public IStatus Status { get; set; }

        #endregion

        #region constructors

        public Asset ( )
        {
            this.AssetRightsUsageList = new List<IAssetRightsUsage> ( );
            this.RelatedAssetList = new List<IRelatedAsset> ( );
            this.AssociatedContentList = new List<IAssociatedContent> ( );
            this.AssetMetaDataList = new List<IMetaData> ( );
            this.AssetContentList = new List<IAssetContent> ( );
        }
        public Asset ( int id , string name , int statusid , string source , DateTime created , DateTime modified , string creator , string editor )
        {
            this.ID = id;
            this.Name = name;
            this.StatusID = statusid;
            this.Source = source;
            this.CreationDate = created;
            this.UpdatedDate = modified;
            this.CreatorID = creator;
            this.LatestEditorID = editor;
            this.AssetRightsUsageList = new List<IAssetRightsUsage> ( );
            this.RelatedAssetList = new List<IRelatedAsset> ( );
            this.AssociatedContentList = new List<IAssociatedContent> ( );
            this.AssetMetaDataList = new List<IMetaData> ( );
            this.AssetContentList = new List<IAssetContent> ( );
        }
        public Asset ( IAsset entity )
        {
            this.ID = entity.ID;
            this.Name = entity.Name;
            this.StatusID = entity.StatusID;
            this.Source = entity.Source;
            this.CreationDate = entity.CreationDate;
            this.UpdatedDate = entity.UpdatedDate;
            this.CreatorID = entity.CreatorID;
            this.LatestEditorID = entity.LatestEditorID;
            this.AssetRightsUsageList = new List<IAssetRightsUsage> ( );
            this.RelatedAssetList = new List<IRelatedAsset> ( );
            this.AssociatedContentList = new List<IAssociatedContent> ( );
            this.AssetMetaDataList = new List<IMetaData> ( );
            this.AssetContentList = new List<IAssetContent> ( );
        }
        public Asset ( IAsset entity , IList<IAssetRightsUsage> assetRightsUsageList )
        {
            this.ID = entity.ID;
            this.Name = entity.Name;
            this.StatusID = entity.StatusID;
            this.Source = entity.Source;
            this.CreationDate = entity.CreationDate;
            this.UpdatedDate = entity.UpdatedDate;
            this.CreatorID = entity.CreatorID;
            this.LatestEditorID = entity.LatestEditorID;
            this.AssetRightsUsageList = assetRightsUsageList;
            this.RelatedAssetList = new List<IRelatedAsset> ( );
            this.AssociatedContentList = new List<IAssociatedContent> ( );
            this.AssetMetaDataList = new List<IMetaData> ( );
            this.AssetContentList = new List<IAssetContent> ( );
        }
        public Asset ( IAsset entity , IList<IRelatedAsset> relatedAssetList )
        {
            this.ID = entity.ID;
            this.Name = entity.Name;
            this.StatusID = entity.StatusID;
            this.Source = entity.Source;
            this.CreationDate = entity.CreationDate;
            this.UpdatedDate = entity.UpdatedDate;
            this.CreatorID = entity.CreatorID;
            this.LatestEditorID = entity.LatestEditorID;
            this.AssetRightsUsageList = new List<IAssetRightsUsage> ( );
            this.RelatedAssetList = relatedAssetList;
            this.AssociatedContentList = new List<IAssociatedContent> ( );
            this.AssetMetaDataList = new List<IMetaData> ( );
            this.AssetContentList = new List<IAssetContent> ( );
        }
        public Asset ( IAsset entity , IList<IAssociatedContent> associatedContentList )
        {
            this.ID = entity.ID;
            this.Name = entity.Name;
            this.StatusID = entity.StatusID;
            this.Source = entity.Source;
            this.CreationDate = entity.CreationDate;
            this.UpdatedDate = entity.UpdatedDate;
            this.CreatorID = entity.CreatorID;
            this.LatestEditorID = entity.LatestEditorID;
            this.AssetRightsUsageList = new List<IAssetRightsUsage> ( );
            this.RelatedAssetList = new List<IRelatedAsset> ( );
            this.AssociatedContentList = associatedContentList;
            this.AssetMetaDataList = new List<IMetaData> ( );
            this.AssetContentList = new List<IAssetContent> ( );
        }

        public Asset ( IAsset entity , IList<IMetaData> assetMetaDataList ) 

        {
            this.ID = entity.ID;
            this.Name = entity.Name;
            this.StatusID = entity.StatusID;
            this.Source = entity.Source;
            this.CreationDate = entity.CreationDate;
            this.UpdatedDate = entity.UpdatedDate;
            this.CreatorID = entity.CreatorID;
            this.LatestEditorID = entity.LatestEditorID;
            this.AssetRightsUsageList = new List<IAssetRightsUsage> ( );
            this.RelatedAssetList = new List<IRelatedAsset> ( );
            this.AssociatedContentList = new List<IAssociatedContent> ( );
            this.AssetMetaDataList = assetMetaDataList;
            this.AssetContentList = new List<IAssetContent> ( );
        }
        public Asset ( IAsset entity , IList<IAssetContent> assetContentList )
        {
            this.ID = entity.ID;
            this.Name = entity.Name;
            this.StatusID = entity.StatusID;
            this.Source = entity.Source;
            this.CreationDate = entity.CreationDate;
            this.UpdatedDate = entity.UpdatedDate;
            this.CreatorID = entity.CreatorID;
            this.LatestEditorID = entity.LatestEditorID;
            this.AssetRightsUsageList = new List<IAssetRightsUsage> ( );
            this.RelatedAssetList = new List<IRelatedAsset> ( );
            this.AssociatedContentList = new List<IAssociatedContent> ( );
            this.AssetMetaDataList = new List<IMetaData> ( );
            this.AssetContentList = assetContentList;
        }
        public Asset ( IAsset entity , IList<IAssetRightsUsage> assetRightsUsageList , IList<IRelatedAsset> relatedAssetList ,

            IList<IAssociatedContent> associatedContentList , IList<IMetaData> assetMetaDataList, IList<IAssetContent> assetContentList )
        {
            this.ID = entity.ID;
            this.Name = entity.Name;
            this.StatusID = entity.StatusID;
            this.Source = entity.Source;
            this.CreationDate = entity.CreationDate;
            this.UpdatedDate = entity.UpdatedDate;
            this.CreatorID = entity.CreatorID;
            this.LatestEditorID = entity.LatestEditorID;
            this.AssetRightsUsageList = assetRightsUsageList;
            this.RelatedAssetList = relatedAssetList;
            this.AssociatedContentList = associatedContentList;
            this.AssetMetaDataList = assetMetaDataList;
            this.AssetContentList = assetContentList;
        }

        #endregion

        #region overridden methods

        public override string ToString ( )
        {
            StringBuilder str = new StringBuilder ( );

            str.Append ( "-> ID: " + this.ID.ToString ( ) );
            str.Append ( "-> Name: " + this.Name );
            str.Append ( "-> StatusID: " + this.StatusID.ToString ( ) );
            str.Append ( "-> Source: " + this.Source );
            if ( this.CreationDate != null ) str.Append ( "-> CreationDate: " + this.CreationDate.ToShortDateString ( ) );
            if ( this.UpdatedDate != null ) str.Append ( "-> UpdatedDate: " + this.UpdatedDate.ToShortDateString ( ) );
            str.Append ( "-> CreatorID: " + this.CreatorID );
            str.Append ( "-> LatestEditorID: " + this.LatestEditorID );

            return str.ToString ( );
        }

        #endregion
    }
}
